<template>
  <div class="app-container calendar-list-container">
    <div class="apply-query">
      <el-row class="filter-query">
        <el-col><i class="el-icon-search"/>&nbsp;&nbsp;筛选查询</el-col>
      </el-row>
      <el-form>
        <el-row>
          <el-col style="margin-bottom: 20px;margin-top: 20px;margin-left: 30px">
            <el-input @keyup.enter.native="handleFilter" style="width: 200px;" class="filter-item" placeholder="操作人姓名"
                      v-model="listQuery.name"></el-input>
            <el-button class="filter-item" type="primary" icon="search" @click="handleFilter">搜索</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <div class="data-list">
      <el-row class="list-content">
        <el-col :span="1" style="text-align: center">
          <svg-icon icon-class="chart"/>
        </el-col>
        <el-col :span="2">数据列表</el-col>
      </el-row>

      <el-table :key="tableKey" :data="list" border fit highlight-current-row style="width:100%">
        <el-table-column align="center" prop="id" label="id">
        </el-table-column>
        <el-table-column align="center" prop="menu" label="菜单">
        </el-table-column>
        <el-table-column prop="opt" align="center" label="操作">
        </el-table-column>
        <el-table-column prop="uri" align="center" label="资源路径">
        </el-table-column>
        <el-table-column prop="createTime" align="center" label="操作时间" :formatter="formatter.formatTimes">
        </el-table-column>
        <el-table-column prop="createBy" align="center" label="操作人ID">
        </el-table-column>
        <el-table-column prop="name" align="center" label="操作人">
        </el-table-column>
        <el-table-column prop="host" align="center" label="操作主机">
        </el-table-column>
      </el-table>
      <div v-show="!listLoading" class="pagination-container">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="listQuery.page"
          :page-sizes="[10, 20, 30, 50, 100, 200]"
          :page-size="listQuery.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
  import {
    page
  } from '@/api/admin/gateLog/index'
  import formatter from '@/utils/formatter'

  export default {
    name: 'gateLog',
    data() {
      return {
        formatter,
        list: null,
        total: null,
        listLoading: true,
        listQuery: {
          page: 1,
          limit: 10,
          crtName: undefined
        },
        dialogFormVisible: false,
        dialogStatus: '',
        gateLogManager_btn_edit: '1',
        gateLogManager_btn_del: '1',
        gateLogManager_btn_add: '1',
        textMap: {
          update: '编辑',
          create: '创建'
        },
        tableKey: 0
      }
    },
    created() {
      this.getQuery()
      this.getList();
    },
    methods: {
      getQuery() {
        const logQuery = window.sessionStorage.getItem('logQuery')
        if (logQuery) {
          this.listQuery = JSON.parse(logQuery)
        }
      },
      getList() {
        this.listLoading = true;
        page(this.listQuery).then(response => {
          this.list = response.data.rows;
          this.total = response.data.total;
          this.listLoading = false;
        })
      },
      handleFilter() {
        this.getList();
      },
      handleSizeChange(val) {
        this.listQuery.limit = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.listQuery.page = val;
        this.getList();
      }
    },
    beforeDestroy() {
      window.sessionStorage.setItem('logQuery', JSON.stringify(this.listQuery))
    }
  }
</script>
